//
//  titleButton.m
//  MixDrinks
//
//  Created by admin on 2016/12/27.
//  Copyright © 2016年 Zhongshan Camry Electronic Company Limited. All rights reserved.
//

#import "titleButton.h"

@implementation titleButton
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = NO;
        [self setTitleColor:colorA(255, 255, 255, 255) forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont systemFontOfSize:22];
        self.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        self.height = self.currentImage.size.height;
    }
    return self;
}

- (void)setTitle:(NSString *)title {
    _title = [title copy];
    [self setTitle:title forState:UIControlStateNormal];
    NSDictionary *atters = @{NSFontAttributeName:self.titleLabel.font};
    CGFloat titleW = [title boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:atters context:nil].size.width;
    self.width = titleW + self.titleEdgeInsets.left + self.currentImage.size.width;
}

@end
